package com.itany.corejava.code08_集合.set集合;

import java.util.Set;
import java.util.TreeSet;

/**
 * @author MissChen
 * @date 2024年03月05日 14:12
 */
public class Test05_Comparator {
    public static void main(String[] args) {
        Set<User2> users=new TreeSet<>(new UserCompator());
        users.add(new User2("admin",22));
        users.add(new User2("jack",22));
        users.add(new User2("aa",18));
        users.add(new User2("alice",18));
        users.add(new User2("root",18));
        System.out.println(users);
    }
}
class User2{
    private String username;
    private int age;

    public User2(String username, int age) {
        this.username = username;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User2{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }
}